package net.thermetics.fx.controllers;

import net.thermetics.fx.features.Feature;
import net.thermetics.fx.services.FeatureService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/features")
public class FeatureController {
	@Autowired
	@Qualifier("featureService")
	private FeatureService featureSvc;
	
	@RequestMapping("{feature}")
	public String getFeature(@PathVariable String feature, ModelMap model) {
		Feature f = featureSvc.getFeature(feature);
		model.addAttribute("feature", f);
		return "feature_info";
	}
	
	@RequestMapping("{feature}/render")
	public @ResponseBody Feature renderFeature(@PathVariable String feature, ModelMap model) {
		Feature f = featureSvc.getFeature(feature);
		model.addAttribute("feature", f);
		return f;
	}
	
	@RequestMapping("{feature}/code/{url}")
	public String renderCode(@PathVariable String feature, @PathVariable String url, ModelMap model) {
		Feature f = featureSvc.getFeature(feature);
		model.addAttribute("feature", f);
		model.addAttribute("url", url);
		return "feature_code";
	}
}
